<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Permission extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('permission')->setComment('权限表');
        $table->addColumn('name', 'string', ['limit' => 255, 'comment' => '权限名称'])
            ->addColumn('description', 'text', ['comment' => '权限描述'])
            ->addColumn('type', 'integer', ['limit' => 4, 'default' => 1, 'comment' => '权限类型：1菜单，2按钮'])
            ->addColumn('parent_id', 'integer', ['limit' => 20, 'default' => 0, 'comment' => '父级ID'])
            ->addColumn('url', 'string', ['limit' => 255, 'comment' => '路由url，格式为module/controller/action'])
            ->addColumn('icon', 'string', ['limit' => 100,'default'=>'', 'comment' => '图标'])
            ->addColumn('sort', 'integer', ['limit' => 4,'default'=>10, 'comment' => '排序权重，默认10，值越小越靠前'])
            ->addColumn('create_user', 'integer', ['limit' => 20, 'comment' => '创建用户ID'])
            ->addColumn('update_user', 'integer', ['limit' => 20, 'comment' => '更新用户ID'])
            ->addTimestamps()//会自动生成timestamp类型的两个字段：create_time  update_time
            ->addSoftDelete()//自动生成timestamp类型的字段：delete_time ，删除时间
            ->create();
    }
}
